package com.iflytek.autofly.setting.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Checkable;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;

import com.iflytek.autofly.setting.R;

/**
 * <b>Description: </b>用于innerlistview作为radiogroup时的item<br/>
 * <b>Change History:</b><br/>
 * <table border="1">
 * <tr>
 * <td><b>user</b></td>
 * <td><b>date</b></td>
 * <td><b>time</b></td>
 * <td><b>reason</b></td>
 * </tr>
 * <tr>
 * <td>JunLuan@iflytek.com</td>
 * <td>2015/11/19</td>
 * <td>17:46</td>
 * <td>创建此文件</td>
 * </tr>
 * </table>
 *
 * @author JunLuan@iflytek.com
 */
public class SpRadioButton extends LinearLayout implements Checkable {

    public TextView mLeftTv;
    public TextView mDescTv;
    public RadioButton mRadioButton;
    private Context mContext;
    private boolean mChecked;

    public SpRadioButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        initView();
    }

    public SpRadioButton(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mContext = context;
        initView();
    }

    public SpRadioButton(Context context) {
        super(context);

        mContext = context;
        initView();
    }

    private void initView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.sp_radio_button, this, false);
        mLeftTv = (TextView) view.findViewById(R.id.left);
        mDescTv = (TextView) view.findViewById(R.id.left_desc);
        mRadioButton = (RadioButton) view.findViewById(R.id.radio_button);
        addView(view);
    }

    @Override
    public boolean isChecked() {
        return mRadioButton.isChecked();
    }

    @Override
    public void setChecked(boolean checked) {
        mRadioButton.setChecked(checked);
    }

    @Override
    public void toggle() {
        mRadioButton.toggle();
    }

    public void setText(String text) {
        mLeftTv.setText(text);
    }

    public void setDesc(String desc) {
        mDescTv.setText(desc);
    }
}
